"getSymbols.wikifolio" <- function(Symbols, env, return.class="xts", Sappend=".vadb", 
                              datefrom="2000-01-01", dateto=NULL, adjust=c("split", "dividend"),
                              user="va", dbname="va_wikifolio", host="localhost", ...) {
  
  addDateClause <- function(sql) {
    if (!is.null(datefrom)) {
      sql <- paste (sql, sprintf ("AND date>='%s'", datefrom))
    }
    if (!is.null(dateto)) {
      sql <- paste (sql, sprintf ("AND date<='%s'", dateto))
    }
    sql <- paste (sql,"ORDER BY `date`")
    return (sql)
  }
  
  
  importDefaults("getSymbols.wikifolio")
  this.env <- environment()
  for(var in names(list(...))) {
    assign(var,list(...)[[var]], this.env)
  }
  
  # additional defaults to be saved
  # used if getSymbolLookup has been set
  # for a specific SYMBOL
  
  default.return.class <- return.class
  
  if(missing(verbose)) verbose <- FALSE
  if(missing(auto.assign)) auto.assign <- TRUE
  
  # connect to database
  con <- connectToVadb(user=user, dbname=dbname, host=host)
  
  for(i in 1:length(Symbols)) {
    # repeat the following 2 assignments for all default arguments
    return.class <- getSymbolLookup()[[Symbols[[i]]]]$return.class
    return.class <- ifelse(is.null(return.class), default.return.class, return.class)
    
    if(verbose) cat("loading ",Symbols[[i]],".....")
    
    # Build SQL Commands
    sql <- sprintf ("SELECT date,open,high,low,close,volume 
                    FROM stockname LEFT JOIN stockprice ON (id=stock_id) WHERE symbol='%s'", Symbols[[i]])
    sql <- addDateClause(sql)
    
    # retrieve Dividends
    sqlDividends <- sprintf("SELECT date,dividend 
                    FROM stockname LEFT JOIN dividends ON (id=stock_id) WHERE symbol='%s'", Symbols[[i]])
    sqlDividends <- addDateClause(sqlDividends)
    
    # retrieve Splits
    sqlSplits <- sprintf ("SELECT date,ratio
                    FROM stockname LEFT JOIN splits ON (id=stock_id) WHERE symbol='%s'", Symbols[[i]])
    sqlSplits <- addDateClause(sqlSplits)

    if (verbose) {
      cat("start of dbGetQuery : ")
      start_t<-Sys.time()
    }

    fr <- dbGetQuery(con, sql)
    div <- dbGetQuery(con, sqlDividends)
    splits <- dbGetQuery(con, sqlSplits)     
    
    if (verbose) {
      cat("end of dbGetQuery : \n")
      end_t<-Sys.time()
      print(end_t-start_t)
    }
    
    # convert to xts object
    fr  <- xts(fr[,-1], as.Date(fr$date), src="vadb", updated=Sys.time())
    if (nrow(div) > 0)   div    <- xts(div[,-1], as.Date(div$date, tz="UTC"))
    if (nrow(splits) >0) splits <- xts(splits[,-1], as.Date(splits$date, tz="UTC")) 
    
    # adjust for dividends/splits: code copied and modified from quantmod's adjustOHLC
    if (is.xts(splits) && is.xts(div) && nrow(splits) > 0 && nrow(div) > 0) {
      div <- div * 1/adjRatios(splits = merge(splits, index(div)))[, 1]
    }
    ratios <- adjRatios(splits, div, Cl(fr))
    if (length(adjust) == 1 && adjust=="split") {
      ratio <- ratios[,1]
    } else if (length(adjust) == 1 && adjust=="dividend") {
      ratio <- ratios[,2]
    } else {
      ratio <- ratios[,1] * ratios[,2]
    }
    Adjusted <- Cl(fr) * ratio
    fr <- structure(cbind((ratio * (Op(fr) - Cl(fr)) + Adjusted), 
                    (ratio * (Hi(fr) - Cl(fr)) + Adjusted), 
                    (ratio * (Lo(fr) - Cl(fr)) + Adjusted), 
                    Adjusted, 
                    if (has.Vo(fr)) Vo(fr)
                      else NULL), 
                    .Dimnames = list(NULL, colnames(fr)))
    
    # change colnames
    colnames(fr) <- paste(toupper(gsub('\\^','',Symbols[[i]])),
                            c('Open','High','Low','Close','Volume'),sep='.')
    
    
    if(auto.assign)
      assign(paste(Symbols[[i]], Sappend, sep=""),fr,env)
    if(verbose)  
      cat("done.\n")
  }
  dbDisconnect(con)
  
  if(auto.assign) return(Symbols)
  return(fr)
  }
